home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / util / processStats.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  3.9 KB  |  198 lines

  1. /*
  2.  *   $RCSfile: processStats.C,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:56:03 $      
  5.  */ 
  6. /*
  7.  * stats.c
  8.  *
  9.  * Member functions for the stats classes.
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include "processStats.h"
  14.  
  15. const int THOU = 1000;
  16.  
  17. extern int IO_DiskReads;
  18. extern int IO_DiskWrites;
  19.  
  20. /*
  21.  * The Start() function starts the collecting of stats
  22.  * for a Unix process.
  23.  */
  24. void
  25. ProcessStats::Start() 
  26. {
  27.     /*
  28.      * Save the current stats in buffer area 1.
  29.      */
  30.     getrusage(RUSAGE_SELF, &rusage1);
  31.     gettimeofday(&time1, NULL);
  32.  
  33.     smPagesRead1 = IO_DiskReads;
  34.     smPagesWrite1 = IO_DiskWrites;
  35.  
  36.     return;
  37. }
  38.  
  39.  
  40. /*
  41.  * The Stop() function stops the collecting of stats
  42.  * for a Unix process.
  43.  */
  44. void
  45. ProcessStats::Stop() 
  46. {
  47.     /*
  48.      * Save the final stats in buffer area 2.
  49.      */
  50.     gettimeofday(&time2, NULL);
  51.     getrusage(RUSAGE_SELF, &rusage2);
  52.  
  53.     smPagesRead2 = IO_DiskReads;
  54.     smPagesWrite2 = IO_DiskWrites;
  55.  
  56.     return;
  57. }
  58.  
  59.  
  60. /*
  61.  * The RealTime() function returns the 
  62.  * elapsed real time in micro-seconds (as measured by Unix) 
  63.  * between the Start() call and the last Stop() call.
  64.  */
  65. float 
  66. ProcessStats::RealTime() 
  67. {
  68.     return 1000000.0 * (time2.tv_sec - time1.tv_sec) + 
  69.            (time2.tv_usec - time1.tv_usec);
  70. }
  71.  
  72.  
  73. /*
  74.  * The UserTime() function returns the Unix process
  75.  * elapsed user time in micro-seconds between the Start() 
  76.  * call and the last Stop() call.
  77.  */
  78. float 
  79. ProcessStats::UserTime() 
  80. {
  81.     return 1000000. * (rusage2.ru_utime.tv_sec - rusage1.ru_utime.tv_sec) +
  82.            (rusage2.ru_utime.tv_usec - rusage1.ru_utime.tv_usec);
  83. }
  84.  
  85.  
  86. /*
  87.  * The SystemTime() function returns the Unix process
  88.  * elapsed system time in micro-seconds between the Start() 
  89.  * call and the last Stop() call.
  90.  */
  91. float 
  92. ProcessStats::SystemTime() 
  93. {
  94.     return 1000000.0 * (rusage2.ru_stime.tv_sec - rusage1.ru_stime.tv_sec) +
  95.            (rusage2.ru_stime.tv_usec - rusage1.ru_stime.tv_usec);
  96. }
  97.  
  98.  
  99. /*
  100.  * The PageRelcaims() function returns the number of 
  101.  * Unix process page reclaims between the Start() call and
  102.  * the last Stop() call.
  103.  */
  104. int
  105. ProcessStats::PageReclaims() 
  106. {
  107.     return rusage2.ru_minflt - rusage1.ru_minflt;
  108. }
  109.  
  110.  
  111. /*
  112.  * The PageFaults() function returns the number of 
  113.  * Unix process page faults between the Start() call and
  114.  * the last Stop() call.
  115.  */
  116. int
  117. ProcessStats::PageFaults() 
  118. {
  119.     return rusage2.ru_majflt - rusage1.ru_majflt;
  120. }
  121.  
  122.  
  123. /*
  124.  * The Swaps() function returns the number of 
  125.  * Unix process swaps between the Start() call and
  126.  * the last Stop() call.
  127.  */
  128. int
  129. ProcessStats::Swaps() 
  130. {
  131.     return rusage2.ru_nswap - rusage1.ru_nswap;
  132. }
  133.  
  134.  
  135. /*
  136.  * The PageIns() function returns the number of
  137.  * Unix page-ins between the Start() call and
  138.  * the last Stop() call.
  139.  */
  140. int
  141. ProcessStats::PageIns() 
  142. {
  143.     return rusage2.ru_inblock - rusage1.ru_inblock;
  144. }
  145.  
  146.  
  147. /*
  148.  * The PageOuts() function returns the number of
  149.  * Unix page-outs between the Start() call and
  150.  * the last Stop() call.
  151.  */
  152. int
  153. ProcessStats::PageOuts() 
  154. {
  155.     return rusage2.ru_oublock - rusage1.ru_oublock;
  156. }
  157.  
  158. /*
  159.  * The smPagesRead() function returns the number of
  160.  * sm pages read between the Start() call and
  161.  * the last Stop() call.
  162.  */
  163. int
  164. ProcessStats::smPagesRead() 
  165. {
  166.     return smPagesRead2 - smPagesRead1;
  167. }
  168.  
  169. /*
  170.  * The smPagesWrite() function returns the number of
  171.  * sm pages written between the Start() call and
  172.  * the last Stop() call.
  173.  */
  174. int
  175. ProcessStats::smPagesWrite() 
  176. {
  177.     return smPagesWrite2 - smPagesWrite1;
  178. }
  179.  
  180. void
  181. ProcessStats::PrintStatsHeader(FILE *f)
  182. {
  183.     fprintf(f, "%-10s %6s %6s %6s %5s %5s %5s %4s %4s %4s %4s\n",
  184.         "        ", "Real", "User", "System", "smIn", "smOut", "Reclm",
  185.         "Pflt", "Swap", "PgIn", "PgOt");
  186. }
  187.  
  188. void
  189. ProcessStats::PrintStats(FILE *f, char *prefix)
  190. {
  191.     fprintf(f, "%-10s %6d %6d %6d %5d %5d %5d %4d %4d %4d %4d\n",
  192.         prefix, (int)(RealTime()/THOU), (int)(UserTime()/THOU),
  193.         (int)(SystemTime()/THOU), smPagesRead(), smPagesWrite(),
  194.         PageReclaims(), PageFaults(), Swaps(), PageIns(), PageOuts());
  195. }
  196.  
  197.  
  198.